# -*- coding: utf-8 -*-
# @Author  : Zhang.Jingyi

# -*- coding: utf-8 -*-
# @Author  : Zhang.Jingyi
import os
import matplotlib.pyplot as plt


def ped_statistic(dataset_path, out_path, mode):
    # bbox expansion factor
    scaleFactor = 1.2

    # structs we need
    imgnames_, scales_, centers_ = [], [], []
    poses_, shapes_, trans_ = [], [], []
    human_vertex_ = []
    point_clouds_, calib_, timastamp_ = [], [], []

    # training/test splits
    if mode == 'train':
        txt_file = os.path.join(dataset_path, 'train.txt')
    elif mode == 'test':
        txt_file = os.path.join(dataset_path, 'test.txt')
    file = open(txt_file, 'r')
    txt_content = file.read()
    bboxs = txt_content.split('\n')
    ignored_values = ["null", " ", None]

    from tqdm import tqdm
    pc_num = []
    for bbox_i in tqdm(bboxs):
        # image name
        info = bbox_i.split('_')
        if len(info) == 1:
            continue

        human_file = '{}_{}_{}.ply'.format(
            info[0], info[2], info[3].strip('.json'))
        human_path = os.path.join(
            dataset_path, 'labels/3d/segment', info[0], human_file)
        if not os.path.exists(human_path):
            continue
        with open(human_path, 'r') as f3:
            human_point = f3.read()
        person_point = []
        person_content = human_point.split('\n')[7:-1]
        if len(person_content) == 0:
            continue
        pc_num.append(len(person_content))
    max_num = max(pc_num)
    min_num = min(pc_num)
    print('max_num:', max_num)
    print('min_num', min_num)
